package com.wd.live.view.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wd.live.R
import com.wd.live.model.bean.StartBean


/**
 * 作者：马海钊
 * 时间：2023/8/15 20:15
 * 功能：
 */
class SexRecyViewAdpater(private val context: Context, private val list: List<StartBean>) :
    RecyclerView.Adapter<SexRecyViewAdpater.ViewHolder?>() {
    private val item = 0
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.sex1_recy_xiao, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val bean = list[position]
        var img = bean.img
        if (bean.isCheck) {
            img = bean.checkimg
        }
        Glide.with(context)
            .load(img)
            .into(holder.imdid)
        holder.imdid.setOnClickListener {
            for (item in list) {
                item.isCheck = false
            }
            bean.isCheck = !bean.isCheck
            notifyDataSetChanged()
        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val imdid: ImageView

        init {
            imdid = itemView.findViewById(R.id.sex1_recy_imgid)
        }
    }
}